package com.th.supcom.pds.phamapply.client.widget.inpharmacyreturn;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.th.supcom.pds.common.client.commom.SimpleMethod;
import com.th.supcom.pds.phamapply.client.model.InpPhamApplyDetailModel;

/**
 * 退药信息面板
 * 
 * @author yzhang
 */
public class InPharmacyReturnMasterGridPanel extends ContentPanel
{
    private Grid <InpPhamApplyDetailModel> m_grid;
    private ListStore <InpPhamApplyDetailModel> m_store;
    private CheckBoxSelectionModel <InpPhamApplyDetailModel> m_checkmodel;

    /**
     * 构造方法
     * 
     * @param drugReturnAndRefundFields
     * @param drugReturnButtons
     */
    public InPharmacyReturnMasterGridPanel ()
    {
        initUI ();
    }

    /**
     * 初始化界面
     */
    private void initUI ()
    {

        setHeaderVisible (false);
        setBorders (false);
        setLayout (new FitLayout ());
        m_checkmodel = new CheckBoxSelectionModel <InpPhamApplyDetailModel> ();
        m_checkmodel.setSelectionMode (SelectionMode.SINGLE);
        m_store = new ListStore <InpPhamApplyDetailModel> ();
        m_grid = new EditorGrid <InpPhamApplyDetailModel> (m_store, createGridHeader (m_checkmodel));
        m_grid.getView ().setEmptyText ("暂时没有您需要的数据...");
        m_grid.setStripeRows (true);
        m_grid.setColumnLines (true);
        m_grid.setBorders (false);
        m_grid.setColumnReordering (true);
        m_grid.setSelectionModel (m_checkmodel);
        m_grid.addPlugin (m_checkmodel);
        add (m_grid);
    }

    private ColumnModel createGridHeader (CheckBoxSelectionModel <InpPhamApplyDetailModel> checkmodel)
    {
        final List <ColumnConfig> columns = new ArrayList <ColumnConfig> ();
        ColumnConfig column = new ColumnConfig ();
        columns.add (checkmodel.getColumn ());

        SimpleMethod.setColumnConfig (column, "patiName", "患者姓名", HorizontalAlignment.LEFT, 60, null);
        columns.add (column);

        column = new ColumnConfig ();
        SimpleMethod.setColumnConfig (column, "bedNo", "床号", HorizontalAlignment.LEFT, 35, null);
        columns.add (column);

        column = new ColumnConfig ();
        SimpleMethod.setColumnConfig (column, "applyNo", "退药单号", HorizontalAlignment.LEFT, 110, null);
        columns.add (column);

        return new ColumnModel (columns);
    }

    /**
     * 加载数据
     * 
     * @param models
     */
    public void refresh (List <InpPhamApplyDetailModel> models)
    {
        m_store.removeAll ();
        m_store.add (models);
    }

    public Grid <InpPhamApplyDetailModel> getGrid ()
    {
        return m_grid;
    }

    public ListStore <InpPhamApplyDetailModel> getStore ()
    {
        return m_store;
    }

    /**
     * 获取表格中的models
     * 
     * @return
     */
    public List <InpPhamApplyDetailModel> getModels ()
    {
        return m_store.getModels ();
    }

    public CheckBoxSelectionModel <InpPhamApplyDetailModel> getCheckmodel ()
    {
        return m_checkmodel;
    }
    
}
